<?php

declare(strict_types=1);

namespace App\Robot\Job;

use App\Robot\Dto\CommonJobDto;
use Hyperf\AsyncQueue\Job;

class CommonJob extends Job
{
    public CommonJobDto $data;

    /**
     * 任务执行失败后的重试次数，即最大执行次数为 $maxAttempts+1 次
     */
    protected int $maxAttempts = 2;

    public function __construct(CommonJobDto $data)
    {
        $this->data = $data;
    }

    public function handle()
    {
        try {
            container()->get($this->data->classname)->{$this->data->method}($this->data->data);
        }catch (\Throwable $e){
            console()->info('commonJob执行失败'.json_encode($this->data,JSON_UNESCAPED_UNICODE).'----'.$e->getMessage());
            logger()->info('commonJob执行失败'.$e->getMessage());
        }
    }

}